package com.huwaiwai001.aqs;


public class TwinsLockTest {

    private static final TwinsLock LOCK = new TwinsLock();

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new T().start();
        }
    }

    private static class T extends Thread {
        @Override
        public void run() {
            String threadName = Thread.currentThread().getName();
            if (!LOCK.tryLock()) {
                LOCK.lock();
            }
            System.out.println(threadName + " lock success");
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            LOCK.unlock();
        }
    }

}
